home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / gtlayout-source.lha / LTP_Clone.c < prev    next >
C/C++ Source or Header  |  1995-06-14  |  8KB  |  327 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8. /*
  9. #undef DB
  10. #define DB(x)    x
  11. */
  12. #ifdef DO_CLONING
  13. VOID __regargs
  14. LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
  15. {
  16.     struct ColorSpec    *ColourSpec    = NULL;
  17.     struct ColourRecord    *ColourRecord    = NULL;
  18.     struct CloneExtra    *Extra = Handle -> CloneExtra;
  19.     LONG             AllocationSize;
  20.     UWORD             i,j,*Pens = Handle -> CloneExtra -> ScreenPens,NumColours;
  21.     struct Screen        *Screen;
  22.     ULONG             DisplayID = GetVPModeID(&Handle -> Screen -> ViewPort);
  23.     UWORD             EndPen = (UWORD)~0;
  24.  
  25.     if(Handle -> ExactClone)
  26.         NumColours = Handle -> Screen -> ViewPort . ColorMap -> Count;
  27.     else
  28.     {
  29.         NumColours = Extra -> TotalPens;
  30.  
  31.         DisplayID &= ~(HAM | EXTRA_HALFBRITE);
  32.     }
  33.  
  34.     Height += Handle -> Screen -> BarHeight + 1;
  35.  
  36.     if(Width < Extra -> MinWidth)
  37.         Width = Extra -> MinWidth;
  38.  
  39.     if(Height < Extra -> MinHeight)
  40.         Height = Extra -> MinHeight;
  41.  
  42.     if(Handle -> SimpleClone)
  43.         Pens = &EndPen;
  44.     else
  45.     {
  46.         if(V39)
  47.         {
  48.             if(!(ColourRecord = (struct ColourRecord *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours)))
  49.             {
  50.                 Handle -> Failed = TRUE;
  51.  
  52.                 DB(kprintf("no colours\n"));
  53.  
  54.                 return;
  55.             }
  56.             else
  57.             {
  58.                 ColourRecord -> NumColours = NumColours;
  59.  
  60.                 if(Handle -> ExactClone)
  61.                     GetRGB32(Handle -> Screen -> ViewPort . ColorMap,0,NumColours,(ULONG *)ColourRecord -> Triplets);
  62.                 else
  63.                 {
  64.                     for(i = 0 ; i < NumColours ; i++)
  65.                         GetRGB32(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i],1,(ULONG *)&ColourRecord -> Triplets[i]);
  66.                 }
  67.             }
  68.         }
  69.         else
  70.         {
  71.             if(!(ColourSpec = (struct ColorSpec *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1))))
  72.             {
  73.                 Handle -> Failed = TRUE;
  74.  
  75.                 DB(kprintf("no colours either\n"));
  76.  
  77.                 return;
  78.             }
  79.             else
  80.             {
  81.                 UWORD RGB;
  82.  
  83.                 if(Handle -> ExactClone)
  84.                 {
  85.                     for(i = 0 ; i < NumColours ; i++)
  86.                     {
  87.                         RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,i);
  88.  
  89.                         ColourSpec[i] . ColorIndex    = i;
  90.                         ColourSpec[i] . Red        = (RGB >> 8) & 0xF;
  91.                         ColourSpec[i] . Green        = (RGB >> 4) & 0xF;
  92.                         ColourSpec[i] . Blue        = (RGB       ) & 0xF;
  93.                     }
  94.                 }
  95.                 else
  96.                 {
  97.                     for(i = 0 ; i < NumColours ; i++)
  98.                     {
  99.                         RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i]);
  100.  
  101.                         ColourSpec[i] . ColorIndex    = i;
  102.                         ColourSpec[i] . Red        = (RGB >> 8) & 0xF;
  103.                         ColourSpec[i] . Green        = (RGB >> 4) & 0xF;
  104.                         ColourSpec[i] . Blue        = (RGB       ) & 0xF;
  105.                     }
  106.                 }
  107.  
  108.                 ColourSpec[i] . ColorIndex = -1;
  109.             }
  110.         }
  111.  
  112.         if(Handle -> ExactClone)
  113.         {
  114.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  115.                 Pens[i] = Extra -> Pens[i];
  116.         }
  117.         else
  118.         {
  119.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  120.             {
  121.                 for(j = 0 ; j < NumColours ; j++)
  122.                 {
  123.                     if(Extra -> Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  124.                     {
  125.                         Pens[i] = j;
  126.  
  127.                         break;
  128.                     }
  129.                 }
  130.             }
  131.         }
  132.  
  133.         Pens[i] = (UWORD)~0;
  134.     }
  135.  
  136.     DB(kprintf("Calling openscreen\n"));
  137.  
  138.     if(Screen = OpenScreenTags(NULL,
  139.         SA_Width,    Width,
  140.         SA_Height,    Height,
  141.         SA_Overscan,    OSCAN_TEXT,
  142.         SA_AutoScroll,    TRUE,
  143.         SA_DisplayID,    DisplayID,
  144.         SA_Behind,    TRUE,
  145.         SA_Depth,    Handle -> SimpleClone ? 2 : Extra -> Depth,
  146.         SA_Colors,    ColourSpec,
  147.         SA_Colors32,    ColourRecord,
  148.         SA_Pens,    Pens,
  149.         SA_Font,    Handle -> TextAttr,
  150.         SA_Title,    Handle -> Screen -> DefaultTitle,
  151.         SA_SharePens,    TRUE,
  152.         SA_Interleaved,    TRUE,
  153.  
  154.         Handle -> SimpleClone ? TAG_IGNORE : SA_BackFill,    &Handle -> BackfillHook,
  155.         Handle -> SimpleClone ? TAG_IGNORE : SA_BlockPen,    Pens[SHADOWPEN],
  156.         Handle -> SimpleClone ? TAG_IGNORE : SA_DetailPen,    Pens[BACKGROUNDPEN],
  157.     TAG_DONE))
  158.     {
  159.         struct DrawInfo *DrawInfo;
  160.  
  161.         DB(kprintf("getting drawinfo\n"));
  162.  
  163.         if(DrawInfo = GetScreenDrawInfo(Screen))
  164.         {
  165.             APTR VisualInfo;
  166.  
  167.             DB(kprintf("getting visualinfo\n"));
  168.  
  169.             if(VisualInfo = GetVisualInfoA(Screen,NULL))
  170.             {
  171.                 UnlockPubScreen(NULL,Handle -> PubScreen);
  172.  
  173.                 FreeScreenDrawInfo(Handle -> Screen,Handle -> DrawInfo);
  174.  
  175.                 FreeVisualInfo(Handle -> VisualInfo);
  176.  
  177.                 Handle -> PubScreen    = NULL;
  178.                 Handle -> Screen    = Screen;
  179.                 Handle -> DrawInfo    = DrawInfo;
  180.                 Handle -> VisualInfo    = VisualInfo;
  181.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  182.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  183.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  184.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  185.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  186.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  187.  
  188.                 if(Handle -> SimpleClone)
  189.                     Handle -> MaxPen = 0;
  190.                 else
  191.                     Handle -> MaxPen = Extra -> TotalPens - 1;
  192.  
  193.                 Extra -> Screen = Screen;
  194.  
  195.                 LTP_Free(Handle,ColourRecord,AllocationSize);
  196.                 LTP_Free(Handle,ColourSpec,AllocationSize);
  197.  
  198.                 DB(kprintf("fertig\n"));
  199.  
  200.                 return;
  201.             }
  202.  
  203.             FreeScreenDrawInfo(Screen,DrawInfo);
  204.         }
  205.  
  206.         CloseScreen(Screen);
  207.     }
  208.  
  209.     LTP_Free(Handle,ColourRecord,AllocationSize);
  210.     LTP_Free(Handle,ColourSpec,AllocationSize);
  211.  
  212.     Handle -> Failed = TRUE;
  213.  
  214.     DB(kprintf("fehlschlag\n"));
  215. }
  216.  
  217. BOOLEAN __regargs
  218. LTP_PrepareCloning(struct LayoutHandle *Handle)
  219. {
  220.     DB(kprintf("prepare cloning\n"));
  221.  
  222.     if(Handle -> CloneExtra)
  223.         return(TRUE);
  224.     else
  225.     {
  226.         struct DimensionInfo DimensionInfo;
  227.  
  228.         DB(kprintf("getting dimensions\n"));
  229.  
  230.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle -> Screen -> ViewPort)))
  231.         {
  232.             DB(kprintf("getting cloneextra\n"));
  233.  
  234.             if(Handle -> CloneExtra = (struct CloneExtra *)LTP_Alloc(Handle,sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle -> DrawInfo -> dri_NumPens + sizeof(UWORD)))
  235.             {
  236.                 UWORD     i,j,TotalPens = 0;
  237.                 LONG    *Pens;
  238.                 BOOLEAN  NotFound;
  239.  
  240.                 Handle -> CloneExtra -> Pens        = (LONG *)(Handle -> CloneExtra + 1);
  241.                 Handle -> CloneExtra -> ScreenPens    = (UWORD *)(&Handle -> CloneExtra -> Pens[Handle -> DrawInfo -> dri_NumPens]);
  242.                 Handle -> CloneExtra -> MinWidth    = DimensionInfo . MinRasterWidth;
  243.                 Handle -> CloneExtra -> MinHeight    = DimensionInfo . MinRasterHeight;
  244.                 Handle -> CloneExtra -> MaxWidth    = DimensionInfo . MaxRasterWidth;
  245.                 Handle -> CloneExtra -> MaxHeight    = DimensionInfo . MaxRasterHeight;
  246.  
  247.                 Handle -> CloneExtra -> Bounds . Left    = 0;
  248.                 Handle -> CloneExtra -> Bounds . Top    = 0;
  249.                 Handle -> CloneExtra -> Bounds . Width    = DimensionInfo . MaxRasterWidth;
  250.                 Handle -> CloneExtra -> Bounds . Height = DimensionInfo . MaxRasterHeight;
  251.  
  252.                 Pens = Handle -> CloneExtra -> Pens;
  253.  
  254.                 if(Handle -> ExactClone)
  255.                 {
  256.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  257.                         Pens[i] = Handle -> DrawInfo -> dri_Pens[i];
  258.  
  259.                     TotalPens = Handle -> DrawInfo -> dri_NumPens;
  260.  
  261.                     Handle -> CloneExtra -> Depth = Handle -> DrawInfo -> dri_Depth;
  262.                 }
  263.                 else
  264.                 {
  265.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  266.                     {
  267.                         for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
  268.                         {
  269.                             if(Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  270.                                 NotFound = FALSE;
  271.                         }
  272.  
  273.                         if(NotFound)
  274.                             Pens[TotalPens++] = Handle -> DrawInfo -> dri_Pens[i];
  275.                     }
  276.  
  277.                     for(i = 0 ; i < DimensionInfo . MaxDepth ; i++)
  278.                     {
  279.                         if(TotalPens <= (1L << i))
  280.                         {
  281.                             Handle -> CloneExtra -> Depth = i;
  282.  
  283.                             break;
  284.                         }
  285.                     }
  286.                 }
  287.  
  288.                 DB(kprintf("totalpens=%ld depth=%ld\n",TotalPens,Handle -> CloneExtra -> Depth));
  289.  
  290.                 if((Handle -> CloneExtra -> TotalPens = TotalPens) && Handle -> CloneExtra -> Depth)
  291.                 {
  292.                     DB(kprintf("setting up glyphs\n"));
  293.  
  294.                     if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
  295.                     {
  296.                         Handle -> Failed = Handle -> Rescaled = FALSE;
  297.  
  298.                         LTP_ResetGroups(Handle -> TopGroup);
  299. /*
  300.                         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  301.                         {
  302.                             LTP_Rescale(Handle,FALSE,FALSE);
  303.  
  304.                             Handle -> Rescaled = FALSE;
  305.                         }
  306. */
  307.                         DB(kprintf("fertig\n\n"));
  308.  
  309.                         return(TRUE);
  310.                     }
  311.                 }
  312.                 else
  313.                 {
  314.                     LTP_Free(Handle,Handle -> CloneExtra,sizeof(struct CloneExtra) + sizeof(LONG) * Handle -> DrawInfo -> dri_NumPens);
  315.  
  316.                     Handle -> CloneExtra = NULL;
  317.                 }
  318.             }
  319.         }
  320.     }
  321.  
  322.     DB(kprintf("fehlschlag\n\n"));
  323.  
  324.     return(FALSE);
  325. }
  326. #endif
  327.